<?php include "include/util/header.php" ?>
<?php include "include/util/menu.php" ?>
<?php 
	include_once "include/commons/IncludeWrapper.php";
	
	$action = new UsuarioAction();
	$evento = Scope::getAttribute("action");

	if( $evento == "search" ) {
		$usuario = new UsuarioBean();
		$nome = Scope::getAttribute("nome");
		$email = Scope::getAttribute("email");
		$usuario->setNome($nome);
		$usuario->setEmail($email);
		$result = $action->search($usuario);
	}
?>
<form action="consulta.php" method="post">
	<input type="hidden" name="action" value="search"/>
	<table width="300">
		<tr>
			<td>Nome</td>
			<td><input type="text" name="nome" value="<?php echo Scope::getAttribute("nome") ?>"/></td>
		</tr>
		<tr>
			<td>E-mail</td>
			<td><input type="text" name="email" value="<?php echo Scope::getAttribute("email") ?>"/></td>
		</tr>
		<tr>
			<td colspan="2"><input type="submit" value="Pesquisar"/></td>
		</tr>
	</table>
</form>

<?php if( $evento == "search" ) { 
		if ( isset($result) && $result != null ) { ?>
			<table border=1>
			  <tr>
			  	<th>ID</th>
			    <th>NOME</th>
			    <th>E-MAIL</th>
			  </tr>
			<?php foreach( $result as $usuario ) { ?>
			  <tr>
			  	<td><?php echo $usuario->getId(); ?></td>
			    <td><?php echo $usuario->getNome(); ?></td>
			    <td><?php echo $usuario->getEmail(); ?></td>
			  </tr>
			<?php } ?>	
			</table>		
	<?php } else { ?>
		Nenhum registro encontrado!
	<?php } ?>
<?php } ?>
<?php include "include/util/footer.php" ?>